<?php
class LoginControl extends Control{
	public function index(){
		$code =new Code;
		
		$this->display('index.html');
	}
//后台登陆 **********************************************************
	// 登陆**********************************************
	public function login(){
		//获得当前POST 的数据
		// var_dump($_POST);
		$username = $_POST['username'];
		$passwd = md5($_POST['password']);
		// var_dump($passwd);die;
		//验证码
		$code = htmlspecialchars($_POST['code']);
		//验证码判断
		if($code!=$_SESSION['code']) $this->error('验证码有误');
		//拼合SQL
		$sql = "SELECT passwd FROM hd_user WHERE username='{$username}' AND power=0";
		//获得数据
		// p($sql);
		$data = M('wenda')->query($sql);
		// p($data);
		if(empty($data)) $this->error('请检查是否开启键盘大小写');
		if($data[0]['passwd']==$passwd){
			//写入SESSION
			$_SESSION['adminName']=$_POST['username'];

			$this->success('成功登陆',__APP__ . '?c=Index');

		}else{
			$this->success('登陆出错,请检查是否开启键盘大小写','admin.php');
		}

}
// 退出************************************************
	public function loginout(){
		//删除SESSION数据文件
			session_destroy();
			//清空SEEION内存文件
			session_unset();
			$this->success('成功退出','admin.php');
	}
	public function code(){
		$code=new Code;
		$code->show();
	}




}